import { getCampusSelector } from '@/api/campus/campus'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import request from '@/utils/request'

export default {
  name: 'account',
  data() {
    return {
      query: {
        brand: 'bell',
        campusId: undefined,
        ruleTitle: undefined
      },
      list: [],
      listLoading: true,
      multipleSelection: [],
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      },
      campusOptions: [],
      brandOptions: [],
      typeOptions: [{ fullName: '人工操作', id: 'Artificial' }, { fullName: '系统操作', id: 'System' }]
    }
  },
  computed: {},
  mounted() {
    getDictionaryDataSelector('Brand').then(res => {
      this.brandOptions = res.data.list
    })
    this.handleChangeBrand('bell')
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      this.listLoading = true
      let _query = {
        ...this.listQuery,
        ...this.query
      }
      let query = {}
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join()
        } else {
          query[key] = _query[key]
        }
      }
      request({
        url: `/api/campus/integral/log/list`,
        method: 'GET',
        data: query
      }).then(res => {
        this.list = res.data.list
        this.total = res.data.pagination.total
        this.listLoading = false
      })
    },
    handleChangeBrand(val) {
      getCampusSelector({ brand: val }).then(res => {
        this.campusOptions = res.data
      })
    },

    handleSelectionChange(val) {
      const res = val.map(item => item.id)
      this.multipleSelection = res
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      }
      this.initData()
    },
    refresh(isrRefresh) {
      this.formVisible = false
      if (isrRefresh) this.reset()
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      }
      this.initData()
    }
  }
}
